#include "Link_list.h"

//单链表的创建

Link_list *init_link_list(void)
{
    //创建头节点的动态空间
    Link_list *list = (Link_list *)malloc(sizeof(Link_list));
    if(NULL == list)
    {
        printf("创建失败\n");
        return NULL;
    }
    list->next = NULL;
    return list;
}

//单链表的销毁
void free_Link_list(Link_list **list)
{
    if(NULL == *list)
    {
        printf("链表为空\n");
        return ;
    }
    //销毁节点
    Node *ptr_1 = (*list)->next;
    Node *ptr_2 = ptr_1->next;
    while(ptr_1 !=NULL)
    {
        free(ptr_1);
        ptr_1 = ptr_2;
        if(NULL != ptr_2)
        {
            ptr_2 = ptr_2->next;
        }
    }
    //销毁头节点
    free(*list);
    *list = NULL;
}

//遍历打印
void printf_link_list(Link_list *list)
{
    if(NULL == list->next)
    {
        printf("表内数据为空\n");
    }
    Node *ptr = list->next;
    while(ptr != NULL)
    {   
        printf("姓名:%s 性别:%s 年龄:%d 成绩:%d 学号:%d\n",
        ptr->data.name,ptr->data.sex,ptr->data.age,ptr->data.sco,ptr->data.id);
        ptr = ptr->next;
    }
}

void tail_insert_node(Link_list *list , Element_data data )
{

	Node *L= (Node*)malloc(sizeof(Node));
	Node *s;
	while(s != NULL){
   		s=(Node*) malloc(sizeof(Node));
   		s->data=data;
  	 	L->next=s;
   		L=s;
	}
	//L->next=NULL;
}